#!/usr/bin/env python

import rospy
from std_srvs.srv import Empty
from roah_devices.srv import Percentage

#switch: number of switch to control (from 1 to 3)
#mode: can be 'on' or 'off'
def switch_control(switch, mode):
	service_str = '/devices/switch_' + str(switch) + '/' + str(mode)
	#print service_str
	try:
		rospy.wait_for_service(service_str)
		handler = rospy.ServiceProxy(service_str, Empty)
		handler() 
	except rospy.ServiceException, e:
		print "Service call failed: %s"%e
	
	
def dimmer_control(perc):
	rospy.wait_for_service('/devices/dimmer/set')
	try:
		handler = rospy.ServiceProxy('/devices/dimmer/set', Percentage)
		handler(perc)
	except rospy.ServiceException, e:
		print "Service call failed: %s"%e
		
def blinds_control(perc):
	rospy.wait_for_service('/devices/blinds/set')
	try:
		handler = rospy.ServiceProxy('/devices/blinds/set', Percentage)
		handler(perc)
	except rospy.ServiceException, e:
		print "Service call failed: %s"%e
	
	
if __name__ == '__main__':
	#print "switching on light 1"
	#switch_control(1, 'on')
	#print "switching on light 2"
	#switch_control(2, 'on')
	#print "switching on light 3"
	#switch_control(3, 'on')
	print "setting dimmer at 50%"
	dimmer_control(0)
	#print "setting belt at 50%"
	#blinds_control(50)
